const jwt = require('jsonwebtoken')

const whiteList=['/login','/register']
const auth = async (ctx, next) => {
    
    if(whiteList.includes(ctx.path)){
        await next()
    }else{
        if (token) {
            let token = ctx.request.header
            try {
                const useInfo = jwt.verify(token, '1906A')
                await next()
            } catch (err) {
                ctx.body = {
                    code: 200,
                    msg: 'token验证成功'
                }
            }
        } else {
            ctx.body = {
                code: 302,
                msg: '无token，请登录'
            }
        }
    }
}

module.exports={auth}